package org.bit.lesson02;

public class Demo208 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            // 通过线程对象内部维护的中断标识，判断当前线程时候否需要被中断
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello thread...");
            }
            System.out.println("线程已退出");
        });
        System.out.println("线程是否存活: " + thread.isAlive());
        thread.start();
        Thread.sleep(1000);
        System.out.println("线程是否存活: " + thread.isAlive());
        // 发出中断信号
        thread.interrupt();
        Thread.sleep(100);
        System.out.println("线程是否存活: " + thread.isAlive());
    }
}
